﻿<UserControl x:Class="CPPEI.Coolzon.Theme.Fashion.MainViewControl.SpeechComment"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
        xmlns:sys="clr-namespace:System;assembly=mscorlib"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" Width="1200" Height="400">
    <UserControl.Resources>
        <!--滚动条默认背景色-->
        <ImageBrush x:Key="imgVerticalScrollBarBackground"
                    TileMode="FlipY"
                    ImageSource="../../Images/Scroll/PageDownBG.png" />
        <!--滚动条上部分已滚动背景色-->
        <ImageBrush x:Key="imgVerticalScrollBarDisabledBackground"
                    TileMode="FlipY"
                    ImageSource="../../Images/Scroll/PageUpBG.png" />
        <!--滚动条上滚动按钮图片-->
        <ImageBrush x:Key="imgVerticalScrollBarUpButton"
                    ImageSource="../../Images/Scroll/BarUp.png" />
        <!--滚动条上滚动按钮不可用状态图片-->
        <ImageBrush x:Key="imgVerticalScrollBarDisabledUpButton"
                    ImageSource="../../Images/Scroll/BarUp_E.png" />
        <!--滚动条下滚动按钮图片 可用 和不可用 都是灰色图片-->
        <ImageBrush x:Key="imgVerticalScrollBarDownButton"
                    ImageSource="../../Images/Scroll/BarDown.png" />
        <!--滚动条中间滚动按钮图片-->
        <BitmapImage x:Key="imgNavigationButton"
                     UriSource="../../Images/Scroll/Nar_Center.png" />
        <!--滚动条中间滚动按钮 滚动时图片-->
        <BitmapImage x:Key="imgNavigationButton_S"
                     UriSource="../../Images/Scroll/Nar_Center_S.png" />
        <!--滚动条的宽度-->
        <sys:Double x:Key="VerticalScrollBarWidth">30</sys:Double>


        <!--ScrollViewer模版-->
        <ControlTemplate x:Key="ScrollViewerControlTemplate1"
                         TargetType="{x:Type ScrollViewer}">
            <Grid x:Name="Grid"
                  Background="{TemplateBinding Background}">

                <!--还是上一话题,我只需要右侧纵向的滚动条,横向滚动条和多余的代码我都去掉了,如果横竖都要用,请照葫芦画瓢,就当是复习了-->
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <!--ScrollViewer左侧内容模版,对它没什么特别的操作,默认就可以-->
                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                        CanContentScroll="{TemplateBinding CanContentScroll}"
                                        CanHorizontallyScroll="False"
                                        CanVerticallyScroll="False"
                                        ContentTemplate="{TemplateBinding ContentTemplate}"
                                        Content="{TemplateBinding Content}"
                                        Grid.Column="0"
                                        Margin="{TemplateBinding Padding}"
                                        Grid.Row="0" />

                <!--ScrollViewer右侧滚动条,编辑它的样式-->
                <ScrollBar x:Name="PART_VerticalScrollBar"
                           AutomationProperties.AutomationId="VerticalScrollBar"
                           Cursor="Arrow"
                           Grid.Column="1"
                           Maximum="{TemplateBinding ScrollableHeight}"
                           Minimum="0"
                           Grid.Row="0"
                           Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"
                           Value="{Binding VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}"
                           ViewportSize="{TemplateBinding ViewportHeight}"
                           Style="{DynamicResource ScrollBarStyle1}" />

            </Grid>
        </ControlTemplate>

        <!--滚动条上下滚动按钮的基样式表-->
        <Style x:Key="RepeatButtonBaseStyle"
               TargetType="{x:Type RepeatButton}">
            <Setter Property="OverridesDefaultStyle"
                    Value="true" />
            <Setter Property="Focusable"
                    Value="false" />
            <Setter Property="IsTabStop"
                    Value="false" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                        <Rectangle x:Name="bg"
                                   Height="{TemplateBinding Height}"
                                   Width="{TemplateBinding Width}"
                                   Fill="{TemplateBinding Background}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!--上滚动区域和下滚动区域的基样式表-->
        <Style x:Key="VerticalScrollBarPageButtonBaseStyle"
               TargetType="{x:Type RepeatButton}">
            <Setter Property="OverridesDefaultStyle"
                    Value="true" />
            <Setter Property="Focusable"
                    Value="false" />
            <Setter Property="IsTabStop"
                    Value="false" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RepeatButton}">
                        <Rectangle Height="{TemplateBinding Height}"
                                   Width="{TemplateBinding Width}"
                                   Fill="{TemplateBinding Background}" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>


        <!--滚动条中间滚动按钮的样式表-->
        <Style x:Key="ThumbStyle1"
               TargetType="{x:Type Thumb}">
            <Setter Property="Stylus.IsPressAndHoldEnabled"
                    Value="false" />
            <Setter Property="Template">

                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">

                        <Image x:Name="image"
                               Stretch="Fill"
                               Source="{StaticResource imgNavigationButton}" />

                        <ControlTemplate.Triggers>
                            <Trigger Property="IsDragging"
                                     Value="True">
                                <Setter Property="Source"
                                        TargetName="image"
                                        Value="{StaticResource imgNavigationButton_S}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>

        </Style>


        <!--滚动条样式表-->
        <Style x:Key="ScrollBarStyle1"
               TargetType="{x:Type ScrollBar}">
            <Setter Property="Stylus.IsPressAndHoldEnabled"
                    Value="false" />
            <Setter Property="Stylus.IsFlicksEnabled"
                    Value="false" />
            <Setter Property="Width"
                    Value="{StaticResource VerticalScrollBarWidth}" />
            <Setter Property="MinWidth"
                    Value="{StaticResource VerticalScrollBarWidth}" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ScrollBar}">
                        <Grid x:Name="Bg"
                              Background="{TemplateBinding Background}"
                              SnapsToDevicePixels="true">
                            <Grid.RowDefinitions>
                                <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}" />
                                <RowDefinition Height="0.00001*" />
                                <RowDefinition MaxHeight="{DynamicResource {x:Static SystemParameters.VerticalScrollBarButtonHeightKey}}" />
                            </Grid.RowDefinitions>

                            <RepeatButton x:Name="rpBtnUp"
                                          Command="{x:Static ScrollBar.LineUpCommand}"
                                          Style="{StaticResource RepeatButtonBaseStyle}"
                                          Background="{StaticResource imgVerticalScrollBarUpButton}"
                                          Foreground="{x:Null}"
                                          BorderBrush="{x:Null}" />

                            <RepeatButton  Grid.Row="2"
                                           x:Name="rpBtnDown"
                                           Command="{x:Static ScrollBar.LineDownCommand}"
                                           Style="{StaticResource RepeatButtonBaseStyle}"
                                           Background="{StaticResource imgVerticalScrollBarDownButton}"
                                           Foreground="{x:Null}"
                                           BorderBrush="{x:Null}" />

                            <Border Grid.Row="1"
                                    x:Name="bdBackground"
                                    Visibility="Collapsed"
                                    Background="{StaticResource imgVerticalScrollBarBackground}">

                            </Border>
                            <Track x:Name="PART_Track"
                                   Grid.Row="1"
                                   IsDirectionReversed="true"
                                   ViewportSize="NaN"
                                   IsEnabled="{TemplateBinding IsMouseOver}">
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton Command="{x:Static ScrollBar.PageUpCommand}"
                                                  Style="{StaticResource VerticalScrollBarPageButtonBaseStyle}"
                                                  Background="{StaticResource imgVerticalScrollBarDisabledBackground}" />
                                </Track.DecreaseRepeatButton>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton Command="{x:Static ScrollBar.PageDownCommand}"
                                                  Style="{StaticResource VerticalScrollBarPageButtonBaseStyle}"
                                                  Background="{StaticResource imgVerticalScrollBarBackground}" />
                                </Track.IncreaseRepeatButton>
                                <Track.Thumb>
                                    <Thumb Style="{StaticResource ThumbStyle1}"
                                           Height="30"
                                           Margin="-2,-14,-1,-14" />
                                </Track.Thumb>
                            </Track>


                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled"
                                     Value="false">
                                <Setter Property="Background"
                                        TargetName="rpBtnUp"
                                        Value="{StaticResource imgVerticalScrollBarDisabledUpButton}" />
                                <Setter Property="Visibility"
                                        TargetName="PART_Track"
                                        Value="Collapsed" />
                                <Setter Property="Visibility"
                                        TargetName="bdBackground"
                                        Value="Visible" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>

        </Style>
    </UserControl.Resources>
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto"   Template="{DynamicResource ScrollViewerControlTemplate1}">
            <RichTextBox x:Name="tbComments" FontSize="30" FontFamily="微软雅黑" Block.LineHeight="40" IsReadOnly="True" BorderThickness="2">
                <FlowDocument>
                    <Paragraph Padding="15,0,15,10" Margin="0,0,0,0" TextIndent="60">
                        <Run x:Name="richTextBoxRun"/>
                    </Paragraph>
                </FlowDocument>
            </RichTextBox>
        </ScrollViewer>
    </Grid>
</UserControl>
